<?php
/**
 * upload.php
 * @author ranuandra
 *
 * 10 Agu 2011 11:23:00
 *
 * 
 */
class Model_Upload extends ORM
{
	protected $_has_many = array(
									'polreg' 	=> array('model' => 'polreg'),
								);
								
	public function getData($form)
	{
		$db = DB::select('uploads.id','uploads.fname', 'uploads.tgl_upload', array(DB::expr('YEAR(polregs.tgl_daftar)'), 'tahun'), array(DB::expr('MONTH(polregs.tgl_daftar)'), 'bulan'))->from('uploads')->join('polregs', 'inner')->on('uploads.id', '=', 'polregs.upload_id');
		
		if($form['bulan'] != "" && $form['tahun'] != "")
		{
			$db = $db->where_open();
			$db = $db->and_where('YEAR(polregs.tgl_daftar)', '=', $form['tahun']);
			$db = $db->and_where('MONTH(polregs.tgl_daftar)', '=', $form['bulan']);
			$db = $db->where_close();
		}
		$db = $db->group_by('polregs.upload_id', DB::expr('YEAR(polregs.tgl_daftar)'), DB::expr('MONTH(polregs.tgl_daftar)'), 'uploads.id','uploads.fname', 'uploads.tgl_upload')
				 ->order_by('YEAR(polregs.tgl_daftar), MONTH(polregs.tgl_daftar)');
		return $db->execute();
	}
}
